package com.yuwubao.uav.tool.controller;

import com.yuwubao.framework.bean.JsonResult;
import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.service.AdService;
import org.apache.poi.util.Removal;
import org.elasticsearch.client.AdminClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("front")
public class ThemeAdFrontAPi {

    @Resource
    private AdService adService;

    @GetMapping("getThemeAdTypes")
    JsonResult getThemeAdTypes() {
        JsonResult result = new JsonResult();
        result.setResult(adService.getAllType());
        result.setSuccessful();
        return result;
    }


    @GetMapping("getThemeAdsByType")
    JsonResult getThemeAdsByType(@RequestParam int id,
                                 @RequestParam(required = false, defaultValue = "1") int page,
                                 @RequestParam(required = false, defaultValue = "8") int pageSize
    ) {
        JsonResult result = new JsonResult();
        PageData pd = new PageData();
        pd.put("index", (page - 1) * pageSize);
        pd.put("size", pageSize);
        pd.put("id", id);
//        result.setResult(adService.getThemeAdsByType(id));
        result.setResult(adService.getThemeAdsByPd(pd));
        result.setResultNum(adService.getThemeAdsNumByPd(pd));
        result.setSuccessful();
        return result;
    }

    @GetMapping("getThemeAdById")
    JsonResult getThemeAdById(@RequestParam int id) {
        JsonResult result = new JsonResult();
        adService.clientThemeAd(id);
        result.setResult(adService.getThemeAdById(id));
        result.setSuccessful();
        return result;
    }

    @GetMapping("getAdTypeByParentId")
    JsonResult getAdTypeByParentId(@RequestParam int id) {
        JsonResult result = new JsonResult();
        result.setResult(adService.getChildTypeById(id));
        result.setSuccessful();
        return result;
    }

    @GetMapping("getAdTypeById")
    JsonResult getAdTypeById(@RequestParam int id
    ) {
        JsonResult result = new JsonResult();
        PageData pd = new PageData();
        result.setResult(adService.getAdTypeByid(id));
        result.setSuccessful();
        return result;
    }
}
